<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>班会签到</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../css/mui.min.css">
		<style>
		.mui-content{
		    background:#fff;
		}
		.mui-input-group .mui-input-row:after{
		    width:96%;left:2%;
		}
		#btn{opacity: 0;}
		</style>
	</head>
		
	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">扫码签到</h1>
		</header>
		        <div class="mui-content">
		            <div class="mui-card">
		                <form class="mui-input-group">
		    <div class="mui-input-row">
		        <label>姓名</label>
		    <input type="text" class="mui-input-clear" id="formname" placeholder="请输入姓名">
		    </div>
		    <div class="mui-input-row">
		        <label>当前位置</label>
		        <input type="text" class="mui-input" id="formsignPlace" placeholder="请输入签到位置">
		    </div>
		    <div class="mui-button-row">
		        <button type="button" id="btn" class="mui-btn mui-btn-primary" >确认签到</button>
		    </div>
		</form>
		            </div>
		        </div>
		<script src="../../../js/mui.min.js"></script>
		<script src="../js/mkeyplus.base.js"></script>
		<script src="http://api.map.baidu.com/api?v=3.0&ak=feLaTL1YEljWzFRGQNs98eUWbN6jPqmv"></script>
		<script>
		var btnSubmit = function(){
			// plus.nativeUI.showWaiting('签到中',{modal:false});
			plus.nativeUI.showWaiting('签到中');
			var config = localStorage.getItem('baseConfig');
			config = config?JSON.parse(config):{};
			var url = config.protocol+config.host+"/smartreport-api/classmetting/j/outClassmettingSign"
			console.log(url)
			mui.ajax(url, 
			{
				data: postData,
				dataType: 'json', //服务器返回json数据
				type: "POST", //http请求类型
				success: function(data) {
					plus.nativeUI.closeWaiting();
					var success = data.success,
					message = data.message
					
					if(success){
						setTimeout(function(){
							mui.back()
						},2000)
						message = '签到成功！'
					}
					mui.toast(message)
				},
				error: function(xhr, type, errorThrown,data) {
					plus.nativeUI.closeWaiting();
					mui.toast('提交遇到错误！')
					console.log(JSON.parse(xhr));
				},
			})

				
		},postData={
			
		}
		mui.init();
		var datas = [];
		var stationname = '';
		mui.plusReady(function () {
			var user = localStorage.getItem('outUser');
			console.log('usesr',user);
			
			 var config = localStorage.getItem('baseConfig');
			 config = config?JSON.parse(config):{};
			 var url = config.protocol+config.host+"/smartreport-api/runLog/j/getAreaStation"
			 console.log(url)
			 mui.ajax(url, 
			 {
			 	data: {},
			 	dataType: 'json', //服务器返回json数据
			 	type: "GET", //http请求类型
			 	success: function(data) {
					datas = data.data;
					var stationid = '';
					var areaId = '';
					if(user){
						stationid = JSON.parse(user).stationId;
						areaId = JSON.parse(user).areaId;
						for (var i = 0; i < datas.length; i++) {
							if(datas[i].areaId == areaId){
								var lists = datas[i].stationList;
								for (var j = 0; j < lists.length; j++) {
									if(lists[j].stationId == stationid){
										stationname = lists[j].stationName
										console.log('stationnam=',stationname);
									}
								}
							}
						}
					}
					
				},
			 	error: function(xhr, type, errorThrown,data) {
					
				},
			 })
			
			
		    var cv = plus.webview.currentWebview();
			
			if(user){
				user = JSON.parse(user);
				postData.signPlace = user.currentProjectName
				document.getElementById('formsignPlace').value = user.currentProjectName
				postData.name = user.compellation
				document.getElementById('formname').value = user.compellation
			}
			
			console.log('cv.mid',cv.mid);
			postData.classMettingId = cv.mid
			plus.geolocation.getCurrentPosition(function(p){
				var coser = new BMap.Geocoder();
			    coser.getLocation(new BMap.Point(p.coords.longitude,p.coords.latitude),function(result){
					postData.signPlace = result.address ||  user.currentProjectName
					document.getElementById('formsignPlace').value = result.address ||  user.currentProjectName
					if(user){
						postData.name = user.compellation
						document.getElementById('formname').value = user.compellation
					}
					document.getElementById('btn').style.opacity = '1'
					plus.nativeUI.closeWaiting();
			    })
			}, function ( e ) {  
			   console.log( "Geolocation error: " + e.message );  
			   if(user){
					postData.signPlace = user.currentProjectName
					document.getElementById('formsignPlace').value = user.currentProjectName
					postData.name = user.compellation
					document.getElementById('formname').value = user.compellation
			   }
			   plus.nativeUI.closeWaiting();
			},{enableHighAccuracy:true,provider:'baidu'});
			plus.nativeUI.showWaiting('读取位置中');
			
			document.getElementById('btn').addEventListener('tap',btnSubmit)
		})
		</script>
	</body>
</html>